package me.zhengjie.modules.system.service.dto

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.annotation.Query
import me.zhengjie.common.utils.JacksonUtil
import org.apache.commons.lang3.builder.ToStringBuilder

import java.sql.Timestamp
import java.time.LocalDateTime

/**
 * @author Kuki Wu
 * @date 2024-11-23
 */
@JsonTypeName("UserQueryCriteria")
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
data class UserQueryCriteria (
    @Query var id: Long?,
    @Query(
        propName = "id",
        type = Query.Type.IN,
        joinName = "dept"
    ) var deptIds: MutableList<Long>?= mutableListOf(),// 多字段模糊
    @Query(blurry = "email,username") var blurry: String? = null,
    @Query var enabled: Boolean? = null,
    var deptId: Long? = null,
    @Query(type = Query.Type.GREATER_THAN, propName = "createTime") var startTime: Timestamp? = null,
    @Query(type = Query.Type.LESS_THAN, propName = "createTime") var endTime: Timestamp? = null
) {
    annotation class Update

    companion object {
        fun fromJson(json: String): UserQueryCriteria? {
            val obj=JacksonUtil.parseObject(json, UserQueryCriteria::class.java)!!
            return when(obj){
                is UserQueryCriteria-> obj
                else -> null
            }
        }
    }
    fun tojson():String? {
        return JacksonUtil.toJSONString(this)
    }

    fun copy(source: UserQueryCriteria?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}